﻿namespace IOP.OpenType.Tables
{
    /// <summary>
    /// 偏移表
    /// </summary>
    public class LocaTable : Table
    {
        /// <summary>
        /// 最大偏移
        /// </summary>
        public uint MaxOffset { get; set; }

        /// <summary>
        /// 偏移
        /// </summary>
        public Offset32[] Offsets { get; set; }
        /// <summary>
        /// 获取字形偏移
        /// </summary>
        /// <param name="glyphId"></param>
        /// <returns></returns>
        public uint GetOffestFromGlyphId(uint glyphId) => Offsets[glyphId];
        /// <summary>
        /// 获取字形偏移以及大小
        /// </summary>
        /// <param name="glyphId"></param>
        /// <returns></returns>
        public (uint, uint) GetOffestAndLengthFromGlyphId(uint glyphId)
        {
            uint offset = Offsets[glyphId];
            uint length = glyphId == Offsets.Length - 1 ? MaxOffset - Offsets[glyphId] : (uint)Offsets[glyphId + 1] - Offsets[glyphId];
            return (offset, length);
        }
    }
}
